package com.ssh.manager.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ssh.common.util.Page;
import com.ssh.dao.IDao;
import com.ssh.entity.ActivityImage;
import com.ssh.entity.Admin;
import com.ssh.entity.Seller;
import com.ssh.entity.SellerAssess;
import com.ssh.manager.AdminManager;
import com.ssh.manager.SellerAssessManager;

@Service
public class SellerAssessManagerImpl implements SellerAssessManager {
	@Resource
	private IDao daoImpl;

	@Override
	public SellerAssess saveUpdate(SellerAssess sellerAssess) {
		return daoImpl.saveOrUpdateDomain(sellerAssess);
	}

	@Override
	public SellerAssess getById(Long id) {
		return daoImpl.getDomain(SellerAssess.class, id);
	}

	@Override
	public void findList(Map conditionMap, Page page, String isDesc) {
		String sql = "select count(*) from SellerAssess";
		String findSql = "from SellerAssess";
		if (conditionMap.get("task")!=null && !conditionMap.get("task").equals("")) {
			sql += " and task.content like '%"+conditionMap.get("task")+"%'";
			findSql += " and task.content like '%"+conditionMap.get("task")+"%'";
		}
		if (conditionMap.get("seller")!=null && !conditionMap.get("seller").equals("")) {
			sql += " and seller.name like '%"+conditionMap.get("seller")+"%'";
			findSql += " and seller.name like '%"+conditionMap.get("seller")+"%'";
		}
		sql = sql.replaceFirst("and", "where");
		findSql = findSql.replaceFirst("and", "where");
		int sum = daoImpl.countAll(sql, null);
		page.setTotalCount(new Long(sum));
		page.countTotalPageNum();
		
		findSql += " order by createDate "+isDesc;
		List<SellerAssess> sellerAssesses = (List<SellerAssess>)daoImpl.findListBySql(findSql, new Object[]{}, false, true, false, page.getNumberPerPage()*(page.getCurPageNum()-1), page.getNumberPerPage());
		page.setPageData(sellerAssesses);
	}

	@Override
	public boolean delete(Long id) {
		try {
			daoImpl.deleteDomain(SellerAssess.class, id);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public SellerAssess add(SellerAssess sellerAssess) {
		// TODO Auto-generated method stub
		return daoImpl.saveOrUpdateDomain(sellerAssess);
	}
	
	public Seller findSellerById( Long  id){
		return daoImpl.getDomain(Seller.class, id);
	}

	
}
